package com.hipmarket.platform.security.service

import com.hipmarket.platform.security.JwtAuthenticationUser
import com.hipmarket.platform.security.service.JwtAuthenticationService
import com.hipmarket.platform.security.storage.JwtAuthenticationStorage
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder

class JwtAuthenticationServiceImpl(private val storage: JwtAuthenticationStorage): JwtAuthenticationService {

    private val passwordEncoder = BCryptPasswordEncoder()

    override fun encode(p0: CharSequence): String {
        return passwordEncoder.encode(p0)
    }

    override fun matches(p0: CharSequence?, p1: String?): Boolean {
        return passwordEncoder.matches(p0, p1)
    }

    override fun login(user: JwtAuthenticationUser): String {
        return storage.login(user)
    }

    override fun login(primaryId: String, userPermissions: List<String>, userRoles: List<String>, userDetails: Any): String {
        return this.login(JwtAuthenticationUser(primaryId, userPermissions, userRoles, userDetails))
    }

    override fun logout(token: String) {
        storage.logout(token)
    }


}